package cn.stylefeng.guns.modular.business.frequency.syssite.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.core.context.login.LoginContextHolder;
import cn.stylefeng.guns.core.exception.ServiceException;
import cn.stylefeng.guns.core.factory.PageFactory;
import cn.stylefeng.guns.core.pojo.page.PageResult;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.modular.business.custom.enums.BonusTypeEnum;
import cn.stylefeng.guns.modular.business.frequency.cmcity.mapper.CmCityMapper;
import cn.stylefeng.guns.modular.business.frequency.cmcompany.model.result.PkgLinkman;
import cn.stylefeng.guns.modular.business.frequency.cmlinkman.mapper.CmLinkmanMapper;
import cn.stylefeng.guns.modular.business.frequency.orderbonus.entity.OrderBonus;
import cn.stylefeng.guns.modular.business.frequency.orderbonus.mapper.OrderBonusMapper;
import cn.stylefeng.guns.modular.business.frequency.orderroyalty.entity.OrderRoyalty;
import cn.stylefeng.guns.modular.business.frequency.orderroyalty.mapper.OrderRoyaltyMapper;
import cn.stylefeng.guns.modular.business.frequency.siterelation.mapper.SiteRelationMapper;
import cn.stylefeng.guns.modular.business.frequency.syssite.entity.SysSite;
import cn.stylefeng.guns.modular.business.frequency.syssite.enums.SysSiteExceptionEnum;
import cn.stylefeng.guns.modular.business.frequency.syssite.mapper.SysSiteMapper;
import cn.stylefeng.guns.modular.business.frequency.syssite.model.param.SysSiteParam;
import cn.stylefeng.guns.modular.business.frequency.syssite.model.result.PkgSite;
import cn.stylefeng.guns.modular.business.frequency.syssite.model.result.SimpleSiteVO;
import cn.stylefeng.guns.modular.business.frequency.syssite.model.result.SiteDTO;
import cn.stylefeng.guns.modular.business.frequency.syssite.service.SysSiteService;
import cn.stylefeng.guns.modular.business.frequency.userawardbase.entity.UserAwardBase;
import cn.stylefeng.guns.modular.business.frequency.userawardbase.model.result.UserAwardBaseResult;
import cn.stylefeng.guns.modular.business.frequency.userawardbase.service.UserAwardBaseService;
import cn.stylefeng.guns.modular.business.util.BusinessUtil;
import cn.stylefeng.guns.sys.modular.org.DeptConstant;
import cn.stylefeng.guns.sys.modular.org.entity.SysOrg;
import cn.stylefeng.guns.sys.modular.org.mapper.SysOrgMapper;
import cn.stylefeng.guns.sys.modular.role.RoleConstant;
import cn.stylefeng.guns.sys.modular.role.entity.SysRole;
import cn.stylefeng.guns.sys.modular.role.mapper.SysRoleMapper;
import cn.stylefeng.guns.sys.modular.user.entity.SysUser;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * sys_site 服务实现类
 *
 * @author yujie
 * @date 2023/05/09 17:17
 */
@Service
public class SysSiteServiceImpl extends ServiceImpl<SysSiteMapper, SysSite> implements SysSiteService {

    @Resource
    private OrderBonusMapper orderBonusMapper;
    @Resource
    private OrderRoyaltyMapper orderRoyaltyMapper;
    @Resource
    private CmLinkmanMapper linkmanMapper;
    @Resource
    private CmCityMapper cmCityMapper;
    @Autowired
    private BusinessUtil businessUtil;
    @Autowired
    private UserAwardBaseService userAwardBaseService;
    @Autowired
    private SiteRelationMapper siteRelationMapper;

    @Autowired
    private SysOrgMapper sysOrgMapper;

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public PageResult<SysSite> page(SysSiteParam sysSiteParam) {

        // 构造条件
        LambdaQueryWrapper<SysSite> queryWrapper = new LambdaQueryWrapper<>();

        // 查询分页结果
        return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper));
    }

    @Override
    public List<SysSite> list(SysSiteParam sysSiteParam) {

        // 构造条件
        LambdaQueryWrapper<SysSite> queryWrapper = new LambdaQueryWrapper<>();

        return this.list(queryWrapper);
    }

    @Override
    public void add(SysSite site) {


        Long tenantId = businessUtil.getTenantId();

        //先查询网点部机构信息
        SysOrg sysOrg = sysOrgMapper.selectOne(new LambdaQueryWrapper<SysOrg>().eq(SysOrg::getTenantId, tenantId)
                .eq(SysOrg::getCode, DeptConstant.网点部编码).eq(SysOrg::getStatus, 0));

        //如果查询为空则直接返回错误
        if (Objects.isNull(sysOrg)) {
            throw new ServiceException(500,"没有网点部门，无法添加网点");
        }

        //根据上传的网点名称去机构表中查。如果能查到记录返回错误信息
        if (Objects.nonNull(sysOrgMapper.selectOne(new LambdaQueryWrapper<SysOrg>().eq(SysOrg::getName, site.getName()).eq(SysOrg::getStatus, 0).eq(SysOrg::getTenantId, tenantId)))) {
            throw new ServiceException(500,"网点名已被占用，请重新输入");
        }


        //直接在机构表中以当前网点信息新增机构，在网点部机构下面
        SysOrg insertSysOrg = new SysOrg();
        insertSysOrg.setPid(sysOrg.getId());
        insertSysOrg.setPids("[0],[" + sysOrg.getId() + "],");
        insertSysOrg.setName(site.getName());
        String uuid = UUID.randomUUID().toString();
        uuid = uuid.replace("_", "");
        uuid = uuid.replace("-", "");
        uuid = uuid.substring(0, 10);
        insertSysOrg.setCode(uuid);
        insertSysOrg.setSort(100);
        insertSysOrg.setStatus(0);
        insertSysOrg.setCreateTime(new Date());
        insertSysOrg.setUpdateTime(new Date());
        insertSysOrg.setCreateUser(LoginContextHolder.me().getSysLoginUserId());
        insertSysOrg.setUpdateUser(LoginContextHolder.me().getSysLoginUserId());
        insertSysOrg.setTenantId(tenantId);
        insertSysOrg.setIsSite(2);

        //查询网点调度的角色id
        SysRole sysRole = sysRoleMapper.selectOne(new LambdaQueryWrapper<SysRole>().eq(SysRole::getCode, RoleConstant.网点部角色)
                .eq(SysRole::getTenantId, tenantId));

        //安全校验
        if (Objects.isNull(sysRole)) {
            throw new ServiceException(500,"当前租户没有网点调度角色");
        }

        insertSysOrg.setRoleId(sysRole.getId());
        //执行新增
        sysOrgMapper.insert(insertSysOrg);

        //接着往网点表中添加记录
        SysSite sysSite = new SysSite();
        sysSite.setCreateTime(new Date());
        sysSite.setUpdateTime(new Date());
        sysSite.setCreateUser(LoginContextHolder.me().getSysLoginUserId());
        sysSite.setUpdateUser(LoginContextHolder.me().getSysLoginUserId());
        sysSite.setName(site.getName());
        sysSite.setRegionCode(site.getRegionCode());
        sysSite.setAddress(site.getAddress());
        sysSite.setHasDelete(0);
        sysSite.setTenantId(tenantId);
        sysSite.setOrgId(insertSysOrg.getId());
        this.getBaseMapper().insert(sysSite);

        //添加网点服务城市
        if (site.getChargeCodeList() != null && site.getChargeCodeList().size() > 0) {
            this.baseMapper.addSiteCity(sysSite.getId().toString(), site.getChargeCodeList(), tenantId);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(SysSiteParam sysSiteParam) {
        this.removeById(sysSiteParam.getId());
    }

    @Override
    public void edit(SysSiteParam sysSiteParam) {

        // 根据id查询实体
        SysSite sysSite = this.querySysSite(sysSiteParam);

        // 请求参数转化为实体
        BeanUtil.copyProperties(sysSiteParam, sysSite);

        this.updateById(sysSite);
    }

    @Override
    public SysSite detail(SysSiteParam sysSiteParam) {
        return this.querySysSite(sysSiteParam);
    }

    @Override
    public List<PkgSite> getSiteList(String month, SiteDTO siteDTO) {
        if (StringUtils.isBlank(month)) {
            // 获取当前月份 yyyy-MM-dd
            String currentDayStr = DateUtil.today();
            month = currentDayStr.substring(0, 7).replace("-", "");
        }
        siteDTO.setTenantId(businessUtil.getTenantId());
        List<PkgSite> siteList = this.baseMapper.getSiteList(siteDTO);
        for (PkgSite site : siteList) {
            // 网点负责城市
            //site.setChargeCodeList(this.baseMapper.getServiceCodes(site.getId()));
            // 网点下的用户
            List<String> userIds = this.baseMapper.getUserIds(site.getId());
            if (userIds != null && userIds.size() > 0) {
                // 奖金明细
                List<OrderBonus> orderBonusList = orderBonusMapper.getByUserIdsAndMonth(userIds, month);
                if (orderBonusList != null && orderBonusList.size() > 0) {
                    // 制单
                    Stream<BigDecimal> stream1 = orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.CREATE_ORDER.type).map(OrderBonus::getFee);
                    site.setCreateFee(stream1.reduce(BigDecimal.ZERO, BigDecimal::add));
                    site.setCreateCount(orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.CREATE_ORDER.type).count());
                    // 提短
                    Stream<BigDecimal> stream2 = orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.FREE_PICK_CAR.type).map(OrderBonus::getFee);
                    site.setPickFreeFee(stream2.reduce(BigDecimal.ZERO, BigDecimal::add));
                    site.setPickFreeCount(orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.FREE_PICK_CAR.type).count());
                    // 验车
                    Stream<BigDecimal> stream3 = orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.VERIFY_CAR.type).map(OrderBonus::getFee);
                    site.setVerifyFee(stream3.reduce(BigDecimal.ZERO, BigDecimal::add));
                    site.setVerifyCount(orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.VERIFY_CAR.type).count());
                    // 发车
                    Stream<BigDecimal> stream4 = orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.TRANSPORT.type).map(OrderBonus::getFee);
                    site.setTransportFee(stream4.reduce(BigDecimal.ZERO, BigDecimal::add));
                    site.setTransportCount(orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.TRANSPORT.type).count());
                    // 交付
                    Stream<BigDecimal> stream5 = orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.DELIVERY.type).map(OrderBonus::getFee);
                    site.setDeliveryFee(stream5.reduce(BigDecimal.ZERO, BigDecimal::add));
                    site.setDeliveryCount(orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.DELIVERY.type).count());
                    // 指派提车
                    Stream<BigDecimal> stream6 = orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.ASSIGN_PICK.type).map(OrderBonus::getFee);
                    site.setPickFee(stream6.reduce(BigDecimal.ZERO, BigDecimal::add));
                    site.setPickCount(orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.ASSIGN_PICK.type).count());
                    // 签收
                    Stream<BigDecimal> stream7 = orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.SIGN.type).map(OrderBonus::getFee);
                    site.setSignFee(stream7.reduce(BigDecimal.ZERO, BigDecimal::add));
                    site.setSignCount(orderBonusList.stream().filter(orderBonus -> orderBonus.getType() == BonusTypeEnum.SIGN.type).count());
                }
                // 提成明细
                List<OrderRoyalty> royaltyList = orderRoyaltyMapper.getListByUserIdsAndMonth(userIds, month);
                if (royaltyList != null && royaltyList.size() > 0) {
                    site.setRoyaltyFee(royaltyList.stream().map(OrderRoyalty::getRoyaltyFee).reduce(BigDecimal.ZERO, BigDecimal::add));
                    site.setRoyaltyCount((long) royaltyList.size());
                }
                // 客户供应商联系人数量
                site.setCompanyCount(linkmanMapper.countByUserIds(userIds));

            }
        }
        // 排序
        if (StringUtils.isNotBlank(siteDTO.getColumn()) && siteDTO.getAsc() != null) {
            if ("createFee".equals(siteDTO.getColumn()) && siteDTO.getAsc()) {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getCreateFee, Comparator.nullsLast(BigDecimal::compareTo))).collect(Collectors.toList());
            } else {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getCreateFee, Comparator.nullsLast(BigDecimal::compareTo)).reversed()).collect(Collectors.toList());
            }
            if ("pickFreeFee".equals(siteDTO.getColumn()) && siteDTO.getAsc()) {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getPickFreeFee, Comparator.nullsLast(BigDecimal::compareTo)).reversed()).collect(Collectors.toList());
            } else {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getPickFreeFee, Comparator.nullsLast(BigDecimal::compareTo)).reversed()).collect(Collectors.toList());
            }
            if ("pickFee".equals(siteDTO.getColumn()) && siteDTO.getAsc()) {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getPickFee, Comparator.nullsLast(BigDecimal::compareTo))).collect(Collectors.toList());
            } else {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getPickFee, Comparator.nullsLast(BigDecimal::compareTo)).reversed()).collect(Collectors.toList());
            }
            if ("verifyFee".equals(siteDTO.getColumn()) && siteDTO.getAsc()) {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getVerifyFee, Comparator.nullsLast(BigDecimal::compareTo))).collect(Collectors.toList());
            } else {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getVerifyFee, Comparator.nullsLast(BigDecimal::compareTo)).reversed()).collect(Collectors.toList());
            }
            if ("transportFee".equals(siteDTO.getColumn()) && siteDTO.getAsc()) {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getTransportFee, Comparator.nullsLast(BigDecimal::compareTo))).collect(Collectors.toList());
            } else {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getTransportFee, Comparator.nullsLast(BigDecimal::compareTo)).reversed()).collect(Collectors.toList());
            }
            if ("signFee".equals(siteDTO.getColumn()) && siteDTO.getAsc()) {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getSignFee, Comparator.nullsLast(BigDecimal::compareTo))).collect(Collectors.toList());
            } else {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getSignFee, Comparator.nullsLast(BigDecimal::compareTo)).reversed()).collect(Collectors.toList());
            }
            if ("deliveryFee".equals(siteDTO.getColumn()) && siteDTO.getAsc()) {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getDeliveryFee, Comparator.nullsLast(BigDecimal::compareTo))).collect(Collectors.toList());
            } else {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getDeliveryFee, Comparator.nullsLast(BigDecimal::compareTo)).reversed()).collect(Collectors.toList());
            }
            if ("royaltyFee".equals(siteDTO.getColumn()) && siteDTO.getAsc()) {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getRoyaltyFee, Comparator.nullsLast(BigDecimal::compareTo))).collect(Collectors.toList());
            } else {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getRoyaltyFee, Comparator.nullsLast(BigDecimal::compareTo)).reversed()).collect(Collectors.toList());
            }
            if ("lineCount".equals(siteDTO.getColumn()) && siteDTO.getAsc()) {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getLineCount, Comparator.nullsLast(Long::compareTo))).collect(Collectors.toList());
            } else {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getLineCount, Comparator.nullsLast(Long::compareTo)).reversed()).collect(Collectors.toList());
            }
            if ("companyCount".equals(siteDTO.getColumn()) && siteDTO.getAsc()) {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getCompanyCount, Comparator.nullsLast(Long::compareTo))).collect(Collectors.toList());
            } else {
                siteList = siteList.stream().sorted(Comparator.comparing(PkgSite::getCompanyCount, Comparator.nullsLast(Long::compareTo)).reversed()).collect(Collectors.toList());
            }
        }
        return siteList;
    }

    @Override
    public Page<PkgLinkman> getCompanyLinkmanList(String id) {
        List<String> userIds = this.baseMapper.getUserIds(id);

        if (userIds != null && userIds.size() > 0) {
            return this.baseMapper.getCompanyLinkmanList(PageFactory.defaultPage(), userIds);
        }
        return new Page<>();
    }

    @Override
    public List<SimpleSiteVO> getSimpleSiteList() {
        return this.baseMapper.getSimpleSiteList();
    }

    @Override
    public List<SysSite> getAllSiteList(SysSite site) {
        //获取当前网点id
        Long siteId = siteRelationMapper.getSiteId(LoginContextHolder.me().getSysLoginUserId());

        LambdaQueryWrapper<SysSite> queryWrapper = new QueryWrapper<SysSite>().lambda()
                .eq(SysSite::getHasDelete, 0)
                .eq(site.getIsShow() != null, SysSite::getIsShow, site.getIsShow())
                .eq(SysSite::getTenantId, businessUtil.getTenantId());
        //修改0218的bug，前登录的网点人员账号在选择到达网点是无法选择自己的网点（截图的是昆明网点人员账号，选择网点时选择不了昆明办事处）
        //因为过滤了自己的网点
//        if (siteId != null) {
//            queryWrapper.ne(SysSite::getId, siteId);
//        }
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public PkgSite getSiteDetail(String id) {
        PkgSite site = this.baseMapper.getSiteDetail(id);
        // 负责城市
        site.setChargeCodeList(this.baseMapper.getServiceCodes(site.getId()));
        return site;
    }

    @Override
    public boolean checkSiteAdd(SysSite site, StringBuilder errorMsg) {
        // 网点名称不可重复
        int count = this.baseMapper.countByName(null, site.getName(), businessUtil.getTenantId());
        if (count > 0) {
            errorMsg.append("网点名称不可重复");
            return false;
        }
        // 服务城市不可重叠
        if (site.getChargeCodeList() != null && site.getChargeCodeList().size() > 0) {
            for (String code : site.getChargeCodeList()) {
                int cityCode = this.baseMapper.countServiceCode(null, code, businessUtil.getTenantId());
                if (cityCode > 0) {
                    errorMsg.append("城市【" + cmCityMapper.getNameByCode(code) + "】已被其他网点绑定，不可重复");
                    return false;
                }
            }
        }
        return true;
    }

    @Override
    public boolean checkSiteUpdate(SysSite site, StringBuilder errorMsg) {
        int count = this.baseMapper.countByName(site.getId().toString(), site.getName(), businessUtil.getTenantId());
        if (count > 0) {
            errorMsg.append("已存在相同名称网点");
            return false;
        }
        // 服务城市不可重叠
        if (site.getChargeCodeList() != null && site.getChargeCodeList().size() > 0) {
            for (String code : site.getChargeCodeList()) {
                int cityCode = this.baseMapper.countServiceCode(site.getId().toString(), code, businessUtil.getTenantId());
                if (cityCode > 0) {
                    errorMsg.append("城市【" + cmCityMapper.getNameByCode(code) + "】已被其他网点绑定，不可重复");
                    return false;
                }
            }
        }
        return true;
    }

    @Override
    public void updateSite(SysSite site) {
        this.baseMapper.updateById(site);
        // 负责城市删除
        this.baseMapper.deleteCityCode(site.getId().toString());
        if (site.getChargeCodeList() != null && site.getChargeCodeList().size() > 0) {
            this.baseMapper.addSiteCity(site.getId().toString(), site.getChargeCodeList(), businessUtil.getTenantId());
        }
    }

    @Override
    public boolean checkSiteDelete(String id, StringBuilder errorMsg) {
    /*    // 网点有没有部门绑定
        int count = this.baseMapper.countDeptBySiteId(id);
        if (count > 0) {
            errorMsg.append("网点已有部门关联，请先取消关联");
            return false;
        }*/
        return true;
    }

    @Override
    public void deleteSite(String id) {
        this.baseMapper.deleteSite(id);
        this.baseMapper.deleteCityCode(id);
    }

    @Override
    public ResponseData getUserList(String id) {
        Long tenantId = businessUtil.getTenantId();
        List<SysUser> list = this.baseMapper.getUserList(id, tenantId);
        return ResponseData.andaSuccess(list);
    }

    @Override
    public List getSiteBonusList(String month) {
        Long tenantId = businessUtil.getTenantId();
        return this.baseMapper.getSiteBonusList(month, tenantId);
    }

    @Override
    public List getSiteRoyaltyList(String month) {
        Long tenantId = businessUtil.getTenantId();
        return this.baseMapper.getSiteRoyaltyList(month, tenantId);
    }

    @Override
    public List getCompanyExportData(String id) {
        List<String> userIds = this.baseMapper.getUserIds(id);
        return this.baseMapper.getCompanyExportData(userIds);
    }

    @Override
    public void addSiteAward(SysSite site) {
        List<UserAwardBase> userAwardBasesList = site.getUserAwardBasesList();
        if (userAwardBasesList != null && userAwardBasesList.size() > 0) {
            Long tenantId = businessUtil.getTenantId();
            for (UserAwardBase userAwardBase : userAwardBasesList) {
                userAwardBase.setTenantId(tenantId);
            }
            userAwardBaseService.saveBatch(userAwardBasesList);
        }

    }

    @Override
    public List<UserAwardBaseResult> userAwardList(SysSite site) {
        List<UserAwardBaseResult> list = this.baseMapper.userAwardList(site.getId());
        return list;
    }

    @Override
    public void userAwardDelelt(Long id) {
        userAwardBaseService.removeById(id);
    }

    @Override
    public void userAwardUpdate(UserAwardBase site) {
        userAwardBaseService.updateById(site);
    }


    /**
     * 获取sys_site
     *
     * @author yujie
     * @since 2023/05/09 17:17
     */
    private SysSite querySysSite(SysSiteParam sysSiteParam) {
        SysSite sysSite = this.getById(sysSiteParam.getId());
        if (ObjectUtil.isEmpty(sysSite)) {
            throw new ServiceException(SysSiteExceptionEnum.NOT_EXISTED);
        }
        return sysSite;
    }
}